import java.util.ArrayList;
import java.util.List;

/**
 * @author oxchains
 * @time 2018-08-30 14:08
 * @name WechatServer
 * @desc:
 */
public class WechatServer implements Observerable {
    private List<Observer> list;

    private String message;

    public WechatServer() {
        this.list = new ArrayList<Observer>();
    }

    public void addObserver(Observer o) {
        list.add(o);
    }

    public void removeObserver(Observer o) {
        if(!list.isEmpty()){
            list.remove(o);
        }
    }

    public void notifyObserver() {
        for(Observer observer : list){
            observer.update(message);
        }
    }

    public void setMessage(String message){
        this.message = message;
        notifyObserver();
    }
}
